<?php
/*
Cogumelo v0.1 - Map-Experience
Copyright (C) 2009 Innoto Gestión para el Desarrollo Social S.L. <mapinfo@map-experience.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
USA.
*/


include_once('Classes/Utils/phpMailer/class.phpmailer.php');
include("Conf/setup.inc");
/*
 * Email sending utility class
 */
class MailSenderPhpMailer
{
	private $headers;
	private $dst;
	private $content;
	private $subject;
	private $mailer;
		
	/*
	 * Class constructor
	 */
	function MailSenderPhpMailer($defaultorg="nobody@nobody.com",$defaultname="Default mailsender name")
	{
	 $this->mailer = new PHPMailer();
	 $this->mailer->IsSendmail();	 
	 $this->mailer->SMTPAuth=smtp_auth;
	 $this->mailer->Host = smtp_host;
	 $this->mailer->Port = smtp_port;
	 $this->mailer->Username = smtp_user;
	 $this->mailer->Password = smtp_pass;
	 $this->mailer->SMTPKeepAlive=true;	 
	 //$this->mailer->IsSendmail();			
	 $this->setOrigin($defaultorg,$defaultname);	 		
	}

	
	/*
    * add an e-mail destination
    */
	function AddDestination($email)
	{	 	
	 $this->mailer->AddAddress($email);
	}
	
	
   /*
    * Reset e-mail destination
    */
	function ResetDestination()
	{
	 $this->mailer->ClearAddresses();
	}
	
	
   /*
    * Set e-mail from orig e-mail and name.
    */
	function SetOrigin($origin,$name)
	{
	 	 
	 $this->mailer->ContentType="text/html";
	 $this->mailer->CharSet="UTF-8";	 
	 $this->mailer->From = $origin;
	 $this->mailer->FromName = $name;
	 
	}


	/*
    * Set Email sending as Bulk
    */
	function SetBulk()
	{	 
	 $this->mailer->AddCustomHeader("Precedence: bulk");
	}
	
	
   /*
    * Set e-mail subject
    */
	function SetSubject($sbjt)
	{	 
	 $this->mailer->Subject=$this->encodeText($sbjt);
	}
	
	
   /*
    * Set e-mail content
    */
	function SetContent($cnt)
	{
	 $this->content = wordwrap($cnt, 80);
	 $this->mailer->MsgHTML($this->content);
	}
	
	
	
	/*
	 * Connect and Disconnect SMTP
	 */
	 function MailConnect()
	 {	 	 	 	
	 }
	
	 /*
	  * Close SMTP Connection
	  */
	function MailClose()
	 {	 		 	
		$this->mailer->SmtpClose();	 		 	 	 	
	 }
	
	
	
   /*
	* Send e-mail buffer to destination
	*/
	function SendMail()
	{	  	   	

	  // $this->setEncoding();
		//encoding specials...
		mb_internal_encoding('UTF-8');
		setlocale(LC_CTYPE, 'es_ES');	  	  
        return($this->mailer->send());       
	}
	
	
	//
	//	encoding settings
	//
	function setEncoding()
	{

	}
	
	
	//
	// return error code
	//
	function getError()
	{
		return($this->mailer->ErrorInfo);
	}
	
	
	function encodeText($textString)
	{
		return $textString;
	}
	
}


?>
